package cn.controller;

import cn.pojo.HealthOrderPerson;
import cn.service.HealthOrderPersonService;
import cn.utils.BaseUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/personO")
public class HealthOrderPersonController {

    @Autowired
    private HealthOrderPersonService personService;

    @PostMapping("/add")
    public Map<String, Object> save(@RequestParam(value = "hospital") String hospital,
                                    @RequestParam(value = "date") String date,
                                    @RequestParam(value = "vaccine") String vaccineId,
                                    @RequestParam(value = "user") String userId,
                                    @RequestParam(value = "kind") Integer kind) {
        HealthOrderPerson person = new HealthOrderPerson();
        person.setOrderHospitalP(hospital);
        person.setOrderDateP(BaseUtils.getTime(date));
        person.setOrderVaccineIdP(vaccineId);
        person.setOrderUserId(userId);
        person.setOrderKindP(kind);
        return personService.save(person);
    }

    @PostMapping("/update")
    public Map<String, Object> update(@RequestParam(value = "hospital") String hospital,
                                      @RequestParam(value = "date") String date,
                                      @RequestParam(value = "vaccine") String vaccineId,
                                      @RequestParam(value = "status", required = false) Integer statusId,
                                      @RequestParam(value = "orderId") Integer orderId,
                                      @RequestParam(value = "orderNo") String orderNo) {
        HealthOrderPerson person = new HealthOrderPerson();
        person.setOrderHospitalP(hospital);
        person.setOrderDateP(BaseUtils.getTime(date));
        person.setOrderVaccineIdP(vaccineId);
        person.setOrderIdP(orderId);
        person.setOrderNoP(orderNo);
        if (statusId != null) {
            person.setOrderStatusP(statusId + 1);
        }
        return personService.update(person);
    }

    @GetMapping("/delete")
    public Map<String, Object> delete (@RequestParam(value = "id") String id,
                                       @RequestParam(value = "no") String no) {
        return personService.delete(id, no);
    }


    @GetMapping("/select")
    public Map<String, Object> select(@RequestParam(value = "user") String userid,
                                      @RequestParam(value = "kind") String kind){
        return personService.select(userid, kind);
    }

}
